package com.yanqu.road.logic.sort;

import com.yanqu.road.entity.activity.seacraft.pirateriot.SeacraftPirateRiotMonsterData;
import com.yanqu.road.entity.activity.seacraft.pirateriot.config.SeacraftPirateRiotConfig;
import com.yanqu.road.entity.activity.seacraft.pirateriot.config.SeacraftPirateRiotMonsterConfig;

import java.util.Comparator;

public class SeacraftPirateRiotMonsterAttackSort implements Comparator<SeacraftPirateRiotMonsterData> {

    private SeacraftPirateRiotConfig config;

    @Override
    public int compare(SeacraftPirateRiotMonsterData o1, SeacraftPirateRiotMonsterData o2) {
        // 比品质，低的先攻
        SeacraftPirateRiotMonsterConfig config1 = config.getMonsterConfigMap().get(o1.getId());
        SeacraftPirateRiotMonsterConfig config2 = config.getMonsterConfigMap().get(o2.getId());
        int qua1 = config1 == null ? 0 : config1.getQuality();
        int qua2 = config2 == null ? 0 : config2.getQuality();
        if (qua1 != qua2) {
            return qua1 - qua2;
        }
        // 比下标，低的先攻
        return o1.getIndex() - o2.getIndex();
    }

    public SeacraftPirateRiotMonsterAttackSort(SeacraftPirateRiotConfig config) {
        this.config = config;
    }

}
